/*
 * File:    Header.java
 * Created: 23-Feb-2009
 * Version: $Id$
 *
 * COPYRIGHT (C) 2009, Bitgate Mobile, LLC.  All Rights Reserved.
 *
 * software@bitgatemobile.com
 */

package com.webplasm.render.tags.u;

import java.util.Arrays;
import java.util.List;

import com.bitgate.util.bytes.ByteString;
import com.webplasm.context.RenderContext;
import com.webplasm.render.engine.RenderException;
import com.webplasm.render.tags.TagInterface;
import com.webplasm.render.tags.WrappedNode;

/**
 * Provides access to HTTP headers sent by the client.
 * 
 * @author kenji
 * @since Webplasm 1.0
 */
public class Header extends WrappedNode implements TagInterface {
	private static final String DESCRIPTION = "Retrieves headers sent by the client request.";

	public String getNamespace() {
		return "u";
	}
	
	public List<String> getAttributes() {
		return Arrays.asList("name");
	}
	
	public List<String> getManagedNodes() {
		return null;
	}

	public String getDescription() {
		return DESCRIPTION;
	}

	@Override
	public StringBuffer render(RenderContext rContext) throws RenderException {
		if (elements.get("name") == null) {
			throw new RenderException("u:header requires a header name.");
		}
		
		return new StringBuffer(rContext.getClientContext().getHeader(new ByteString(elements.get("name"))).toString());
	}
}